package com.example.mystore.mapper;

import com.example.mystore.model.Product;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;

@Mapper
public interface UserCommodityMapper {

    @Select("SELECT id, name, product_id AS productId, parts_id AS partsId, icon_url AS iconUrl, sub_images AS subImages, detail, spec_param AS specParam, price, stock, status, is_hot AS isHot, created, updated " +
            "FROM commodity WHERE is_hot = 1 AND status = 2")
    List<Product> getHotUserCommodities();
    @Select("SELECT id, name, product_id AS productId, parts_id AS partsId, icon_url AS iconUrl, sub_images AS subImages, detail, spec_param AS specParam, price, stock, status, is_hot AS isHot, created, updated " +
            "FROM commodity WHERE product_id = #{productId} AND status = 2")
    List<Product> getProductsByProductId(@Param("productId") Integer productId);

    @Select("SELECT id, name, product_id AS productId, parts_id AS partsId, icon_url AS iconUrl, sub_images AS subImages, detail, spec_param AS specParam, price, stock, status, is_hot AS isHot, created, updated " +
            "FROM commodity WHERE name LIKE CONCAT('%', #{keyword}, '%') AND status = 2")
    List<Product> searchProductsByKeyword(@Param("keyword") String keyword);
}
